max_attempts = 5  # 最大尝试次数  
attempts = 0

while attempts < max_attempts:
    try:

        break  # 成功获取数据后退出循环
    except Exception as err:
        print(f"An error occurred: {err}")
    attempts += 1
    print('跳出循环是否会继续执行')
    # 可以选择在这里加入延时，避免过快重试导致的服务器压力
    if attempts < max_attempts:
        print(f"Retrying in {attempts * 2} seconds...")

print('完成')